﻿using App.Model;
using System.Collections.Generic;
using System.Windows.Forms;

namespace App.UI
{
    internal class MainArea : SplitContainer
    {
        public Table<string> table;
        public LineChart Chart { set; get; }

        private HslLineChart hslLineChart;

        private List<string[]> _dataCache = new List<string[]>();

        public MainArea()
        {
            this.Dock = DockStyle.Fill;

            this.Orientation = Orientation.Horizontal;

            this.BorderStyle = BorderStyle.Fixed3D;

            table = new Table<string>();
            table.Visible = false;

           // Chart = new LineChart();
            hslLineChart = new HslLineChart();
            hslLineChart.onDataMove += HslLineChart_onDataMove;
            this.Panel1.Controls.Add(hslLineChart);
            this.Panel2.Controls.Add(table);

            this.AllowDrop = true;
            this.DragEnter += HandleDragEnter;
            this.DragDrop += HandleDragDrop;

            table.AllowDrop = true;
            table.DragEnter += HandleDragEnter;
            table.DragDrop += HandleDragDrop;
        }

        private void HslLineChart_onDataMove(object sender, HslLineChart.RecordEvent e)
        {
            table.SetHeader(e.Header);
            table.SetData(e.Data);
            table.Visible = true;
        }

        private void HandleDragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("LineSeries"))
            {
                e.Effect = DragDropEffects.Copy;
            }
        }

        private void HandleDragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("LineSeries"))
            {
                Drager drager = (Drager)e.Data.GetData("LineSeries");
                if (drager != null)
                {
                    table.SetHeader(drager.Names);
                  //  table.SetData(drager.getData());
                    table.Visible = true;
                }
            }
        }

    }
}
